<?php 
/*
$JA#COPYRIGHT$
*/

// Check to ensure this file is included in Joomla!
defined('_JEXEC') or die( 'Restricted access' );
class JElementEmployer extends JElement
{
	/*
	 * Element name
	 *
	 * @access	protected
	 * @var		string
	 */
	var	$_name = 'Employer';
	function fetchElement($name, $value, &$node, $control_name)
	{
		$arrOpt = array();
		$options = $this->getEmployerList();
		for($i=0; $i < count($options); $i++){		
			$arrOpt[$i]['keys'] = $options[$i]->id;
			$arrOpt[$i]['value'] = $options[$i]->company; 
		}		
		
		return JHTML::_('select.genericlist',  $arrOpt, ''.$control_name.'['.$name.'][]', 'class="inputbox" multiple=""', 'keys', 'value', $value, $control_name.$name );		
	}
	
	function getEmployerList()
	{
		$db = JFactory::getDBO();
		$query = "SELECT p.id,p.company FROM #__ja_profiles AS p ".
				 "\n INNER JOIN #__ja_employers as e ON e.user_id=p.user_id ".
				 "\n INNER JOIN #__users as rs ON rs.id=p.user_id".
				 "\n WHERE e.featured=1".
				 "\n ORDER BY ordering";
//		$query = "SELECT p.id,p.company FROM #__ja_profiles AS p WHERE ";
//		$query .= " p.logo<>''";
		$db->setQuery( $query );
		$options = $db->loadObjectList();
		return $options;
	}
}

?>
